package operation;

import book.Book;
import book.Bookshelf;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    public void work(Bookshelf bookshelf) {
        System.out.println("借阅图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅的书名");
        String name = scanner.nextLine();

        int cur = bookshelf.getUsedSize();
        for (int i = 0; i < cur; i++) {
            Book book = bookshelf.getBook(i);
            if (name.equals(book.getName())) {
                //查看借阅状态
                if (book.isBorrowed()) {
                    System.out.println("已被借阅，无法借阅");
                } else {
                    book.setBorrowed(true);
                    System.out.println("借阅成功");
                }
                return;
            }
        }

        //没有找到
        System.out.println("没有此书");
    }
}